package domain;
// Generated 26-jun-2009 19:31:47 by Hibernate Tools 3.2.1.GA


import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Bankaccount generated by hbm2java
 */
@Entity
@Table(name="bankaccount"
    ,catalog="domeco"
)
public class Bankaccount  implements java.io.Serializable {


     private Integer idBank;
     private Userdom userdom;
     private String name;
     private Set<Invoice> invoices = new HashSet<Invoice>(0);
     private Set<Income> incomes = new HashSet<Income>(0);
     private Set<Expense> expenses = new HashSet<Expense>(0);
     private Set<Salary> salaries = new HashSet<Salary>(0);
     private Set<Contract> contracts = new HashSet<Contract>(0);

    public Bankaccount() {
    }

	
    public Bankaccount(Userdom userdom, String name) {
        this.userdom = userdom;
        this.name = name;
    }
    public Bankaccount(Userdom userdom, String name, Set<Invoice> invoices, Set<Income> incomes, Set<Expense> expenses, Set<Salary> salaries, Set<Contract> contracts) {
       this.userdom = userdom;
       this.name = name;
       this.invoices = invoices;
       this.incomes = incomes;
       this.expenses = expenses;
       this.salaries = salaries;
       this.contracts = contracts;
    }
   
     @Id @GeneratedValue(strategy=IDENTITY)
    
    @Column(name="idBank", unique=true, nullable=false)
    public Integer getIdBank() {
        return this.idBank;
    }
    
    public void setIdBank(Integer idBank) {
        this.idBank = idBank;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="userFK", nullable=false)
    public Userdom getUserdom() {
        return this.userdom;
    }
    
    public void setUserdom(Userdom userdom) {
        this.userdom = userdom;
    }
    
    @Column(name="name", nullable=false, length=50)
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="bankaccount")
    public Set<Invoice> getInvoices() {
        return this.invoices;
    }
    
    public void setInvoices(Set<Invoice> invoices) {
        this.invoices = invoices;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="bankaccount")
    public Set<Income> getIncomes() {
        return this.incomes;
    }
    
    public void setIncomes(Set<Income> incomes) {
        this.incomes = incomes;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="bankaccount")
    public Set<Expense> getExpenses() {
        return this.expenses;
    }
    
    public void setExpenses(Set<Expense> expenses) {
        this.expenses = expenses;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="bankaccount")
    public Set<Salary> getSalaries() {
        return this.salaries;
    }
    
    public void setSalaries(Set<Salary> salaries) {
        this.salaries = salaries;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="bankaccount")
    public Set<Contract> getContracts() {
        return this.contracts;
    }
    
    public void setContracts(Set<Contract> contracts) {
        this.contracts = contracts;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idBank != null ? idBank.hashCode() : 0);
        return hash;
    }

    public Contract getContract(int idC) {
        Contract cont = null;
        for (Iterator it = this.getContracts().iterator(); it.hasNext();) {
            Contract c = (Contract) it.next();
            if (c.getIdContract().compareTo(idC) == 0) {
                cont = c;
            }
        }
        return cont;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Bankaccount)) {
            return false;
        }
        Bankaccount other = (Bankaccount) object;
        if ((this.idBank == null && other.idBank != null) || (this.idBank != null && !this.idBank.equals(other.idBank))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "domain.Bankaccount[idBank=" + idBank + "]";
    }




}


